package com.example.mobie2030606155byl0407;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private TextView tvMainTitle;
    private Button btnchongzhi;
    private TextView tvMainwenti1;
    private RadioGroup rdgxuanxian1;
    private RadioButton Radbtn1A;
    private RadioButton Radbtn1B;
    private RadioButton Radbtn1C;
    private RadioButton Radbtn1D;
    private TextView tvMainwenti2;
    private RadioGroup rdgxuanxian2;
    private RadioButton Radbtn2A;
    private RadioButton Radbtn2B;
    private RadioButton Radbtn2C;
    private RadioButton Radbtn2D;
    private TextView tvMainwenti3;
    private RadioGroup rdgxuanxian3;
    private RadioButton Radbtn3A;
    private RadioButton Radbtn3B;
    private RadioButton Radbtn3C;
    private RadioButton Radbtn3D;
    private TextView tvMainwenti4;
    private RadioGroup rdgxuanxian4;
    private RadioButton Radbtn4A;
    private RadioButton Radbtn4B;
    private RadioButton Radbtn4C;
    private RadioButton Radbtn4D;
    private Button btntijiao;
    private TextView tvfenshu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnchongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Radbtn1A.setChecked(false);
                Radbtn1B.setChecked(false);
                Radbtn1C.setChecked(false);
                Radbtn1D.setChecked(false);
                Radbtn2A.setChecked(false);
                Radbtn2B.setChecked(false);
                Radbtn2C.setChecked(false);
                Radbtn2D.setChecked(false);
                Radbtn3A.setChecked(false);
                Radbtn3B.setChecked(false);
                Radbtn3C.setChecked(false);
                Radbtn3D.setChecked(false);
                Radbtn4A.setChecked(false);
                Radbtn4B.setChecked(false);
                Radbtn4C.setChecked(false);
                Radbtn4D.setChecked(false);
                tvfenshu.setText("");
                Toast.makeText(MainActivity.this,"重置成功",Toast.LENGTH_SHORT).show();
            }
        });
        rdgxuanxian1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                Log.i( "第一题选择为: ",radBtn.getText().toString());
            }
        });
        rdgxuanxian2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                Log.i( "第二题选择为: ",radBtn.getText().toString());
            }
        });
        rdgxuanxian3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                Log.i( "第三题选择为: ",radBtn.getText().toString());
            }
        });
        rdgxuanxian4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                Log.i( "第四题选择为: ",radBtn.getText().toString());
            }
        });
        btntijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int checkedID1 = rdgxuanxian1.getCheckedRadioButtonId();
                int checkedID2 = rdgxuanxian2.getCheckedRadioButtonId();
                int checkedID3 = rdgxuanxian3.getCheckedRadioButtonId();
                int checkedID4 = rdgxuanxian4.getCheckedRadioButtonId();
                if (checkedID1 == R.id.Radbtn1A & checkedID2==R.id.Radbtn2C & checkedID3==R.id.Radbtn3B & checkedID4==R.id.Radbtn4A) {
                    tvfenshu.setText("分数为100分");
                } else if (checkedID1 == R.id.Radbtn1A & checkedID2==R.id.Radbtn2B & checkedID3==R.id.Radbtn3B || checkedID2==R.id.Radbtn2C &
                        checkedID3==R.id.Radbtn3B & checkedID4==R.id.Radbtn4A || checkedID1 == R.id.Radbtn1A& checkedID3==R.id.Radbtn3B & checkedID4==R.id.Radbtn4A) {
                    tvfenshu.setText("分数为75分");
                }else if (checkedID1 == R.id.Radbtn1A & checkedID2==R.id.Radbtn2C || checkedID1 == R.id.Radbtn1A& checkedID3==R.id.Radbtn3B||
                        checkedID1 == R.id.Radbtn1A& checkedID4==R.id.Radbtn4A|| checkedID2==R.id.Radbtn2C & checkedID3==R.id.Radbtn3B||
                        checkedID2==R.id.Radbtn2C & checkedID4==R.id.Radbtn4A|| checkedID3==R.id.Radbtn3B & checkedID4==R.id.Radbtn4A){
                    tvfenshu.setText("分数为50分");
                }else if (checkedID1 == R.id.Radbtn1A  || checkedID2==R.id.Radbtn2C  || checkedID3==R.id.Radbtn3B || checkedID4==R.id.Radbtn4A){
                    tvfenshu.setText("分数为25分");
                }else if (checkedID1==-1||checkedID2==-1||checkedID3==-1||checkedID4==-1 ){
                    Toast.makeText(MainActivity.this, "请作出选择", Toast.LENGTH_SHORT).show();
                }else{
                    tvfenshu.setText("分数为0分");
                }
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnchongzhi = (Button) findViewById(R.id.btn_chongzhi);
        tvMainwenti1 = (TextView) findViewById(R.id.tv_main_wenti1);
        rdgxuanxian1 = (RadioGroup) findViewById(R.id.rdg_xuanxian1);
        Radbtn1A = (RadioButton) findViewById(R.id.Radbtn1A);
        Radbtn1B = (RadioButton) findViewById(R.id.Radbtn1B);
        Radbtn1C = (RadioButton) findViewById(R.id.Radbtn1C);
        Radbtn1D = (RadioButton) findViewById(R.id.Radbtn1D);
        tvMainwenti2 = (TextView) findViewById(R.id.tv_main_wenti2);
        rdgxuanxian2 = (RadioGroup) findViewById(R.id.rdg_xuanxian2);
        Radbtn2A = (RadioButton) findViewById(R.id.Radbtn2A);
        Radbtn2B = (RadioButton) findViewById(R.id.Radbtn2B);
        Radbtn2C = (RadioButton) findViewById(R.id.Radbtn2C);
        Radbtn2D = (RadioButton) findViewById(R.id.Radbtn2D);
        tvMainwenti3 = (TextView) findViewById(R.id.tv_main_wenti3);
        rdgxuanxian3 = (RadioGroup) findViewById(R.id.rdg_xuanxian3);
        Radbtn3A = (RadioButton) findViewById(R.id.Radbtn3A);
        Radbtn3B = (RadioButton) findViewById(R.id.Radbtn3B);
        Radbtn3C = (RadioButton) findViewById(R.id.Radbtn3C);
        Radbtn3D = (RadioButton) findViewById(R.id.Radbtn3D);
        tvMainwenti4 = (TextView) findViewById(R.id.tv_main_wenti4);
        rdgxuanxian4 = (RadioGroup) findViewById(R.id.rdg_xuanxian4);
        Radbtn4A = (RadioButton) findViewById(R.id.Radbtn4A);
        Radbtn4B = (RadioButton) findViewById(R.id.Radbtn4B);
        Radbtn4C = (RadioButton) findViewById(R.id.Radbtn4C);
        Radbtn4D = (RadioButton) findViewById(R.id.Radbtn4D);
        btntijiao = (Button) findViewById(R.id.btn_tijiao);
        tvfenshu = (TextView) findViewById(R.id.tv_fenshu);
    }
}